package com.example.demo

import java.lang.StringBuilder
import java.security.*
import java.util.*

fun main() {
    val pwd = encode("erupt", "erupt")
    println("pwd=$pwd")
}

fun md5(src: String): String {
    val md5 = MessageDigest.getInstance("MD5")
    md5.update(src.toByteArray())
    val byteDigest = md5.digest().asList()
    val sb = StringBuilder()
    for (offset in byteDigest.indices) {
        var i: Int = byteDigest[offset].toInt() and 0xff
        if (i < 0) {
            i += 256
        }
        if (i < 16) {
            sb.append("0")
        }
        sb.append(Integer.toHexString(i))
    }
    return sb.toString()
}

fun encode(account: String, password: String): String {
    val calendar = Calendar.getInstance()
    calendar.time = Date()
    val date = calendar.get(Calendar.DATE)
    return md5(md5(password) + date.toString() + account)
}


